package com.macro.mall.portal.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.Provincemapping;
import com.macro.mall.portal.service.CnRegionInfoService;
import com.macro.mall.portal.service.ProvincemappingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * province的路由接口服务
 *
 * @author
 */
@RestController
@RequestMapping("province")
@Api(tags = "ProvinceController", description = "省份管理")
public class ProvinceController {

    /**
     * PmsSiteService服务
     */
    @Autowired
    private ProvincemappingService provinceService;
    @Autowired
    private CnRegionInfoService cnRegionInfoService;

    /**
     * 查询所有PmsSite数据的方法
     *
     * @return
     */
    @ApiOperation("查询list")
    @RequestMapping(value = "/list",  method = RequestMethod.GET)
    public CommonResult find(@ApiParam(value = "province") @RequestParam(value = "province", defaultValue = "") String province,
                             @ApiParam(value = "level 1-省, 2-市 3-区") @RequestParam(value = "level", defaultValue = "") String level,
                             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                             @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize ) {
        List<Provincemapping> provincemappings = provinceService.find(Provincemapping.builder().code(province).build(), pageNum, pageSize);
        return CommonResult.success(CommonPage.restPage(provincemappings));
    }

    /**
     * 查询所有PmsSite数据的方法
     *
     * @return
     */
    @ApiOperation("查询分组list")
    @RequestMapping(value = "/groupList",  method = RequestMethod.GET)
    public CommonResult groupList() {
        Map<String, Object> provincemappings = cnRegionInfoService.findGroupList();
        return CommonResult.success(provincemappings);
    }

   /* @ApiOperation("查询分组list")
    @RequestMapping(value = "/findGroupListById",  method = RequestMethod.GET)
    public CommonResult findGroupListById(@ApiParam(value = "code") @RequestParam(value = "code", defaultValue = "") String code,
                                          @ApiParam(value = "level 1-省, 2-市 3-区") @RequestParam(value = "level", defaultValue = "") String level) {
        List<List<CnRegionInfoList>> a = new ArrayList();
        List<List<CnRegionInfoList>> b = new ArrayList();

        List<CnRegionInfo> provincemappings = cnRegionInfoService.findGroupListById(code, level);
        for(CnRegionInfo one : provincemappings) {
            List<CnRegionInfoList> list = new ArrayList<>();
            for(CnRegionInfoList c : one.getList()) {
                List<CnRegionInfoList1> list1 = new ArrayList<>();
            }
            a.add(list);
        }

        return CommonResult.success(a);
    }*/
}
